# -*- coding: utf-8 -*-
#
# Author:: Jonny
# Date:: 2022/4/20
import os
import random
from time import sleep

gravity_map = {
    "左": ["0,50,0", "0,-50,0"],
    "左上1": ["20,60,0", "-20,-60,0"],
    "左上2": ["20,40,0", "-20,-40,0"],
    "左上3": ["20,20,0", "-20,-20,0"],
    "左上4": ["60,20,0", "-60,-20,0"],
    "左上5": ["40,20,0", "-40,-20,0"],
    "上": ["50,0,0", "-50,0,0"],
    "右上1": ["20,-60,0", "-20,60,0"],
    "右上2": ["20,-40,0", "-20,40,0"],
    "右上3": ["20,-20,0", "-20,20,0"],
    "右上4": ["60,-20,0", "-60,20,0"],
    "右上5": ["40,-20,0", "-40,20,0"],
}


def exec_call_gravity(gravity_data):
    # 复位 0,0,0无效，通过移动的中点操作模拟复位
    cmd_str_tmp = f"ldconsole action --name A --key call.gravity --value 50,0,0"
    print(cmd_str_tmp)
    os.popen(cmd_str_tmp)
    sleep(float(random.uniform(1, 3)))
    cmd_str_tmp = f"ldconsole action --name A --key call.gravity --value -50,0,0"
    print(cmd_str_tmp)
    os.popen(cmd_str_tmp)
    sleep(float(random.uniform(1, 3)))

    if len(gravity_data) < 1:
        return

    data0 = gravity_data[0]
    data1 = gravity_data[1]
    cmd_str_tmp = f"ldconsole action --name A --key call.gravity --value {data0}"
    print(cmd_str_tmp)
    os.popen(cmd_str_tmp)
    sleep(2)
    cmd_str_tmp = f"ldconsole action --name A --key call.gravity --value {data1}"
    print(cmd_str_tmp)
    os.popen(cmd_str_tmp)
    sleep(2)


def main():
    for gravity_data in gravity_map.values():
        exec_call_gravity(gravity_data)


if __name__ == "__main__":
    while True:
        main()
